--ffscreen
include('shared.lua')

function ENT:Draw()
	self.Entity:DrawModel()
	
	self:RenderScreen()
end

function ENT:RenderScreen()
	-- Align screen to prop
	local ang = self.Entity:GetAngles()
	local rot = Vector(-90,90,0) -- face forwards
	ang:RotateAroundAxis(ang:Right(), 	rot.x)
	ang:RotateAroundAxis(ang:Up(), 		rot.y)
	ang:RotateAroundAxis(ang:Forward(), rot.z)
	
	local onscreen = false

	local pos = self.Entity:GetPos() + (self.Entity:GetForward() * self.fixedvector.x) + (self.Entity:GetUp() * self.fixedvector.y) + (self.Entity:GetRight() * self.fixedvector.z)
	
	local cpos, trent = self:Getcpos(LocalPlayer())
	if (trent == self.Entity) && (cpos.x >= 0) && (cpos.x <= self.size.x) && (cpos.y >= 0) && (cpos.y <= self.size.y) then onscreen = true end
	
	cpos.x = cpos.x * self.res
	cpos.y = cpos.y * self.res
	local size = self.size * self.res
	
	cam.Start3D2D(pos, ang, 1/self.res)

		surface.SetDrawColor(250,250,255,255)
		surface.DrawRect(0,0,size.x,size.y)
		
		surface.SetDrawColor(100,100,100,255)
		
		surface.DrawRect( self.btnPay.x - self.btnPay.w/2, self.btnPay.y, self.btnPay.w, self.btnPay.h )
		if self:Hovered(cpos,self.btnPay.x - self.btnPay.w/2, self.btnPay.y, self.btnPay.w, self.btnPay.h) then
			surface.SetDrawColor(0,255,0,255)
			surface.DrawOutlinedRect( self.btnPay.x - self.btnPay.w/2, self.btnPay.y, self.btnPay.w, self.btnPay.h )
		end
		
		draw.SimpleText( "£"..self:GetNetworkedInt( "cost",0 ), "TargetID", self.btnPay.x, self.btnPay.y+self.btnPay.h/2,  Color(255,255,255,255),  1,1 )
		
		draw.SimpleText( self:GetNetworkedString( "label","RIDE NAME" ), "TargetID", size.x/2, size.y*0.1,  Color(0,0,0,255),  1,1 )
		
		
		if onscreen then
			surface.SetTexture(surface.GetTextureID("gui/arrow"))
			surface.SetDrawColor(0,0,0,255)
			surface.DrawTexturedRectRotated(cpos.x+5,cpos.y+5,16,16,45)
			surface.SetDrawColor(255,255,255,255)
			surface.DrawTexturedRectRotated(cpos.x+5,cpos.y+5,14,14,45)
		end
		
	cam.End3D2D()
end


--function ENT:Drawtranslucent()
	
--end